#!/bin/bash
#
# Copyright (C) 2017 ~ 2018 Deepin Technology Co., Ltd.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
#

# Setup keyboard layout and model.
setup_keyboard() {
  local XKBLAYOUT XKBVARIANT XKBMODEL XKBOPTIONS
  XKBLAYOUT=$(installer_get "DI_LAYOUT")
  XKBVARIANT=$(installer_get "DI_LAYOUT_VARIANT")
  XKBMODEL=$(installer_get "DI_KEYBOARD_MODEL")
  XKBOPTIONS=$(installer_get "DI_KEYBOARD_OPTIONS")

  XKBMODEL=${XKBMODEL:-pc105}
  XKBLAYOUT=${XKBLAYOUT:-us}

  cat > /etc/default/keyboard << EOF
# Check /usr/share/doc/keyboard-configuration/README.Debian for
# documentation on what to do after having modified this file.

# The following variables describe your keyboard and can have the same
# values as the XkbModel, XkbLayout, XkbVariant and XkbOptions options
# in /etc/X11/xorg.conf.

XKBMODEL="${XKBMODEL}"
XKBLAYOUT="${XKBLAYOUT}"
XKBVARIANT="${XKBVARIANT}"
XKBOPTIONS="${XKBOPTIONS}"

# If you don't want to use the XKB layout on the console, you can
# specify an alternative keymap.  Make sure it will be accessible
# before /usr is mounted.
# KMAP=/etc/console-setup/defkeymap.kmap.gz
EOF
}

if [ x$(installer_get "system_info_setup_after_reboot") != xtrue ]; then
  setup_keyboard
fi
